<template>
    <div style="width: 100%">
        <div id="deawer">
            <v-tableTitle :title="$t('wave.savefilter')" :btnConfig="btnConfig" @cancel="cancel" @save="save"
                          @wave="wave"></v-tableTitle>
            <div class="detailBox">
                <v-detail ref="detail"></v-detail>
            </div>
            <div class="detailListBox">
                <v-detailList ref="detailList"></v-detailList>
            </div>
        </div>
    </div>

</template>

<script>
import baseMixin from "@/mixins/BaseMixin";
import skipMixin from "@/mixins/SkipMixin";
import config from "../Config"
import tableTitle from "commons/TableTitle";
import detail from "../details/Detail"
import detailList from "../detailsList/DetailList"

export default {
    name: "",
    mixins: [baseMixin, skipMixin, config],
    data() {
        return {
            newFlag: false,
            routeData: {}
        };
    },
    computed: {
        btnConfig() {
            return [
                {label: this.$t('wave.savefilter'), certigier: this.saveStatus||!this.btnPermNameList.includes('WM05020102'), invalid: "save"},
                {label: this.$t('wave.showorderlist'), certigier: this.queryListStatus||!this.btnPermNameList.includes('WM05020103'), invalid: "wave"},
                {label: this.$t('common.return'), certigier: !this.btnPermNameList.includes('WM05020104'), invalid: "cancel"},
            ]
        }
    },
    created() {
    },
    methods: {
        wave() {
            this.$router.push({name: "savefilterWave", query: {queryPageFlag: "savefilter"}});
        },
        //保存按钮
        async save() {
            let flag = this.$refs.detail.$children[0].$refs.input.submitForm("from");
            if (!flag) {
                return;
            }
            let data = {};
            let detail = this.$refs.detail.detailData;
            let detailList = this.$refs.detailList.detailData;
            if (this.$refs.detailList.detailsFlag) {
                let detailflag = this.$refs.detailList.$children[1].$refs.input.submitForm("from");
                if (!detailflag) {
                    return;
                }
                data = {
                    ...detail,
                    wpFilterdetails: [
                        {
                            ...detailList,
                            filterid: detail.filterid
                        }
                    ]
                }

            } else {
                data = {
                    ...detail,
                }
            }
            try {
                let res = await this.$api.post(`/insertWpFilter/${this.routeData.rtxwavetype}`, data);
                
                    this.$message.success(res.returnMgr);
                    this.$refs.detailList.detailsFlag = false;
                    this.$refs.detailList.detailNav = "1";

                
            } catch (e) {
                this.$message.error(e)
            }
        },
        //弹框取消
        cancel() {
            this.$router.push({name: "savefilter"});
        },
    },
    mounted() {
        if (Object.keys(this.$store.state.skip).length !== 0) {
            let data = this.$store.state.skip;
            this.routeData = data.routeData;
            this.$store.commit("setRouteData", data.routeData);
            this.newFlag = data.newFlag;
        } else {
            this.routeData = this.$store.state.routeData;
            this.newFlag = this.$store.state.newFlag;
        }

    },
    watch: {},
    components: {
        "v-tableTitle": tableTitle,
        "v-detail": detail,
        "v-detailList": detailList,
    }
}
</script>

<style scoped>

</style>
